
/**
 * 
 */
package com.zsrt.day20170414.homework;


import java.util.Scanner;

import org.junit.Before;
import org.junit.Test;

import com.zsrt.utils.ArrayUtil;



/**
 * 学生的测试类
 * @author jmj
 * @date 2017年4月14日
 * @time 下午6:14:02
 */
public class StudentDaoImplTest {
	
	Student[] students = new Student[6];
	studentDaoImpl student = new studentDaoImpl();
	@Before
	public void Before(){
		
		Student jmj=new Student();
		jmj.setName("贾梦菊");
		
		jmj.setAge(21);
		students[0]=jmj;
		Student zjy=new Student();
		zjy.setName("张嘉源");
		zjy.setAge(22);
		students[1]=zjy;
		Student lzh=new Student();
		lzh.setName("罗智壕");
		lzh.setAge(23);
		students[2]=lzh;
		Student hxq=new Student();
		hxq.setName("何小强");
		hxq.setAge(28);
		students[3]=hxq;
		Student jzh=new Student();
		jzh.setName("靳志辉");
		jzh.setAge(25);
		students[4]=jzh;
		Student zc=new Student();
		zc.setName("周驰");
		zc.setAge(26);
		students[5]=zc;
	}
	
	/**
	 * 增加一个学生
	 * @throws Exception
	 */
	@Test
	public void addTest() throws Exception {
		Scanner scanner = new Scanner(System.in);
		
		Student [] newStudents = new  Student[students.length+1];
		
		System.out.println("请输入您插入的学生的姓名：");
		String name = scanner.nextLine();
		System.out.println("请输入您插入的学生的年龄：");
		 int age = scanner.nextInt();
		scanner.close();
		if(name.length()>=2  && name.length()<=4){
			if(age>0 && age<120){
				 newStudents =student.add(name, age, students);
			}
		}
		ArrayUtil.StudentEntity(newStudents);
	}
	
	/**
	 * 通过名字来查询该学生是否在数组中 然后将修改后的age值赋给ta
	 * @throws Exception
	 */
	@Test
	public void updateTest() throws Exception {
		Student [] newStudents = new  Student[students.length];
		newStudents = student.update("贾梦菊", 26, students);
		ArrayUtil.StudentEntity(newStudents);
	}
	
	
	/**
	 * 通过名字来查询学生
	 * @throws Exception
	 */
	@Test
	public void searchTest() throws Exception {
		int index = student.searchByName("靳志辉", students);
		if(index !=-1){
			
			System.out.println("该学生在数组中，其下标为"+index);
		}else{
			System.out.println("该学生不在这个数组中。");
		}
	}
	
	/**
	 * 查询年龄在target或以上的学生
	 * @throws Exception
	 */
	@Test
	public void searchByAgeTest() throws Exception {
		int target = 23;
		student.searchByAge(students, target);
	}
	
	/**
	 * 删除一个学生
	 * @throws Exception
	 */
	@Test
	public void deleteTest() throws Exception {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入你的手机号码");
		String phone1 = scanner.nextLine();
		System.out.println("请输入你的登录密码");
		String password1 = scanner.nextLine();
		if(phone1.equals("13926583118")){
			if(password1.equals("123456")){
				
				Student [] newStudents = new  Student[students.length-1];
				String name = "贾梦菊";
				newStudents=student.delete(name , students);
				ArrayUtil.StudentEntity(newStudents);
			}else{
				System.out.println("您没有权限删除学生，谢谢合作！");
			}
		}else{
			System.out.println("您没有权限删除学生，谢谢合作！");
		}
		scanner.close();
	}
	
	/**
	 * 删除一批学生
	 * @throws Exception
	 */
	@Test
	public void deleteSomeTest() throws Exception {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入你的手机号码");
		String phone1 = scanner.nextLine();
		System.out.println("请输入你的登录密码");
		String password1 = scanner.nextLine();
		if(phone1.equals("13926583118")){
			if(password1.equals("123456")){
				
				String[] names = {"贾梦菊","罗智壕","林华华"};
				student.deleteSome(names , students);
			}else{
				System.out.println("您没有权限删除学生，谢谢合作！");
			}
		}else{
			System.out.println("您没有权限删除学生，谢谢合作！");
		}
		scanner.close();
	}
	
	

}
